<?php
namespace Home\Controller;
use Think\Controller;
class IntroductionController extends Controller 
{
    public function index()
    {
    	$id=I('get.id/d');

    	$com = M('comment');
        //查询评论
        $comment=$com->field('user.name,user.icon,comment.gid,comment.content,comment.time')->join('user on user.id = comment.uid')->where(array('gid'=>$id))->select();
        // var_dump($comment);die;
    	$this->assign('comment',$comment);

        //创建足迹
        if(empty($_SESSION['User'])){
            
        }else{
            // var_dump($_SESSION);
            $uid = $_SESSION['User']['uid'];
            $gid = $id;
            $foot['uid'] = $uid;
            $foot['gid'] = $gid;
            $foot['time'] = date('Y-m-d');
            $fot = M('foot');
            // var_dump($foot);die;
            if($fot->create($foot)){
                //查看是否已经有数据了
                $result = $fot->where($foot)->select();
                if(empty($result)){
                    //没有数据就添加数据
                    $fot->add();
                }else{
                    // 有数据了就啥都不做
                }
            }
        }
        
        //查询优惠劵
        $cup = M('coupon');
        $clist = $cup->where(array('gid'=>$id,'status'=>'1'))->select();
        // var_dump($clist);
        $this->assign('clist',$clist);


    	$data=M('goodsimg')->where(array('gid'=>$id))->select();
    	$this->assign('data',$data);

        $data1 = M('goods')->field('goods.gname,goodsimg.gid,goodsimg.icon,goodsimg.face,goods.id,goods.cid,goods.price,goods.stock,goods.cknum,goods.sales,goods.up,goods.hot,goods.des,goods.uptime')->join('goodsimg on goods.id=goodsimg.gid')->where(array('face'=>1,'goods.id'=>$id))->select();
        $this->assign('data1',$data1);
        
        $list=D('Goodscategory')->where('pid=1')->select();
        $this->assign('list',$list);
        
        $this->display(); 

        
    }

    //优惠劵
    public function coupon(){
        // var_dump($_SESSION);
        // var_dump($_GET);
        $cid = $_GET['id'];
        $cup = M('coupon');
        $clist = $cup->where(array('id'=>$cid))->select();
        // var_dump($clist);
        // unset($_SESSION['Coupon']);
        $_SESSION['Coupon'][$cid] = $clist[0];
        var_dump($_SESSION);
    }

    

}